<?php
/**
 * php生成全球唯一标识符Guid
 * @return Guid
 */
function create_Guid(){
	// 生成uuid
	$uuid = uniqid(mt_rand(), true);
	// md5加密并转大写
	$Guidkey = strtoupper(md5($uuid));
	// 生成Guid
	$Guid = substr($Guidkey, 0, 8) . '-';
	$Guid .= substr($Guidkey, 8, 4) . '-';
	$Guid .= substr($Guidkey, 12, 4) . '-';
	$Guid .= substr($Guidkey, 16, 4) . '-';
	$Guid .= substr($Guidkey, 20, 12);
	return $Guid;
}

/**
 * php提供的官方的函数
 * @return Guid
 */
function Guid(){
	if (function_exists('com_create_guid')) {
		return com_create_guid();
	} else {
		mt_srand((double) microtime() * 10000); //optional for php 4.2.0 and up.
		$charid = strtoupper(md5(uniqid(rand(), true)));
		$hyphen = chr(45); // '-'
		$uuid = substr($charid, 0, 8) . $hyphen
		$uuid .= substr($charid, 8, 4) . $hyphen
		$uuid .= substr($charid, 12, 4) . $hyphen
		$uuid .= substr($charid, 16, 4) . $hyphen
		$uuid .= substr($charid, 20, 12);
		return $uuid;
	}
}

// 打印数据
$Guid = create_Guid();
var_dump($Guid);